<?php 
namespace Qwadmin\Controller;

class ExportController extends ComController
{






	//行政汇总月度申请导出
	public function xdao()
	{
		$dertime = date('Y-m-d');
		// echo $dertime;
		// exit;
		$clist = M('look')->order('time desc')->where(['type'=>3,'look'=>2,'ju'=>0])->select();
		// dump($clist);
		// exit;
		foreach ($clist as  $v) {
			$coun += $v['zong']; 
		}
		// $ctime = $clist[0]['time'];

		// $ulist = M('ucan')->where(['time'=>$ctime])->select();
		$clist[0]['coun'] = $coun.'/元';
         // dump($clist);
         //   exit;

        if (!empty($clist)) {
             
           
          
            
            $tableHeader = array(
                '编号','物品名称', '申请数量', '物品单价','申请时间','申请部门','总价格'
            );
            $tableCols = array(
                'id','wname','num', 'unit','time','ment','coun'
            );
            downloadExcel($clist, $tableHeader,$tableCols, 'pcs'.'.xls');
        }else{
            $this->error('没有数据可以导出,请检查!');
            exit;
        }



	}




	//行政临时物品申请导出
	public function ldao()
	{
		// $dertime = date('Y-m-d');
		// echo $dertime;
		// exit;
		$clist = M('look')->order('ment desc')->where(['type'=>['neq',3],'look'=>2,'ju'=>0])->select();
		// dump($clist);
		// exit;
		foreach ($clist as  $v) {
			$coun += $v['zong']; 
		}
		// $ctime = $clist[0]['time'];

		// $ulist = M('ucan')->where(['time'=>$ctime])->select();
		$clist[0]['coun'] = $coun.'/元';
         // dump($clist);
         //   exit;

        if (!empty($clist)) {
             
           
          
            
            $tableHeader = array(
                '编号','物品名称', '申请数量', '物品单价','申请时间','申请部门','单个总价','总价格'
            );
            $tableCols = array(
                'id','wname','num', 'unit','time','ment','zong','coun'
            );
            downloadExcel($clist, $tableHeader,$tableCols, 'pcs'.'.xls');
        }else{
            $this->error('没有数据可以导出,请检查!');
            exit;
        }



	}






	//行政临时物品申请导出
	public function suoyou()
	{

		// dump($_GET);
		// exit;
		switch ($_GET['type']) {
			case '1':
				$clist = M('look')->order('ment desc')->where(['type'=>2,'look'=>6,'ju'=>0])->select();
				if (!empty($clist)) {
             
           
            
		            $tableHeader = array(
		                '编号','物品名称', '申请数量', '物品单价','申请时间','申请部门','单个总价'
		            );
		            $tableCols = array(
		                'id','wname','num', 'unit','time','ment','zong'
		            );
		            downloadExcel($clist, $tableHeader,$tableCols, 'pcs'.'.xls');
		        }else{
		            $this->error('没有数据可以导出,请检查!');
		            exit;
		        }
				break;
			case '2':
				$clist = M('look')->order('ment desc')->where(['type'=>0,'look'=>3,'ju'=>0])->select();
				if (!empty($clist)) {
             
           
            
		            $tableHeader = array(
		                '编号','物品名称', '申请数量', '物品单价','申请时间','申请部门','单个总价'
		            );
		            $tableCols = array(
		                'id','wname','num', 'unit','time','ment','zong'
		            );
		            downloadExcel($clist, $tableHeader,$tableCols, 'pcs'.'.xls');
		        }else{
		            $this->error('没有数据可以导出,请检查!');
		            exit;
		        }
				break;
			case '3':
				$clist = M('look')->order('ment desc')->where(['type'=>1,'look'=>6,'ju'=>0])->select();
				if (!empty($clist)) {
             
           
            
		            $tableHeader = array(
		                '编号','物品名称', '申请数量', '物品单价','申请时间','申请部门','单个总价'
		            );
		            $tableCols = array(
		                'id','wname','num', 'unit','time','ment','zong'
		            );
		            downloadExcel($clist, $tableHeader,$tableCols, 'pcs'.'.xls');
		        }else{
		            $this->error('没有数据可以导出,请检查!');
		            exit;
		        }
				break;
			
		}

		// $dertime = date('Y-m-d');
		// echo $dertime;
		// exit;
		$clist = M('look')->order('ment desc')->where(['type'=>['neq',3],'look'=>2,'ju'=>0])->select();
		// dump($clist);
		// exit;
		foreach ($clist as  $v) {
			$coun += $v['zong']; 
		}
		// $ctime = $clist[0]['time'];

		// $ulist = M('ucan')->where(['time'=>$ctime])->select();
		$clist[0]['coun'] = $coun.'/元';
         // dump($clist);
         //   exit;

        if (!empty($clist)) {
             
           
          
            
            $tableHeader = array(
                '编号','物品名称', '申请数量', '物品单价','申请时间','申请部门','单个总价','总价格'
            );
            $tableCols = array(
                'id','wname','num', 'unit','time','ment','zong','coun'
            );
            downloadExcel($clist, $tableHeader,$tableCols, 'pcs'.'.xls');
        }else{
            $this->error('没有数据可以导出,请检查!');
            exit;
        }



	}


	//所有通过月度申请导出
	public function yzong()
	{
		// $dertime = date('Y-m-d');
		// echo $dertime;
		// exit;
		$ylist = M('look')->where(['type'=>3,'look'=>6,'ju'=>0])->select();
		// dump($ylist);
		// exit;
		foreach ($ylist as  $v) {
			$coun += $v['zong']; 
		}
		// $ctime = $clist[0]['time'];

		// $ulist = M('ucan')->where(['time'=>$ctime])->select();
		$ylist[0]['coun'] = $coun.'/元';
         // dump($clist);
         //   exit;

        if (!empty($ylist)) {
             
           
          
            
            $tableHeader = array(
                '编号','物品名称', '申请数量', '物品单价','申请时间','申请部门','总价格'
            );
            $tableCols = array(
                'id','wname','num', 'unit','time','ment','coun'
            );
            downloadExcel($ylist, $tableHeader,$tableCols, 'pcs'.'.xls');
        }else{
            $this->error('没有数据可以导出,请检查!');
            exit;
        }



	}














	//急性物品申请审批导出
	public function jdao()
	{
		$dertime = date('Y-m-d');
		// echo $dertime;
		// exit;
		$clist = M('look')->order('time desc')->where(['type'=>1,'look'=>2,'ju'=>0])->select();
		// dump($clist);
		// exit;
		// foreach ($clist as  $v) {
		// 	$coun += $v['zong']; 
		// }
		// $ctime = $clist[0]['time'];

		// $ulist = M('ucan')->where(['time'=>$ctime])->select();
		// $clist[0]['coun'] = $coun.'/元';
         // dump($clist);
         //   exit;

        if (!empty($clist)) {
             
           
          
            
            $tableHeader = array(
                '编号','品名', '规格', '单位','数量','预估单价','备注','申请人','所属部门'
            );
            $tableCols = array(
                'id','wname','xing', 'com','num','unit','content','uname','ment'
            );
            downloadExcel($clist, $tableHeader,$tableCols, 'pcs'.'.xls');
        }else{
            $this->error('没有数据可以导出,请检查!');
            exit;
        }



	}



	//派车反馈信息导出
	public function cdao()
	{
		if (empty($_GET['type'])) {
				$dertime = date('Y-m-d');
				// echo $dertime;
				// exit;
				$clist = M('hui')->order('id desc')->where(['type'=>1])->select();
				// dump($clist);
				// exit;
				// foreach ($clist as  $v) {
				// 	$coun += $v['zong']; 
				// }
				// $ctime = $clist[0]['time'];

				// $ulist = M('ucan')->where(['time'=>$ctime])->select();
				// $clist[0]['coun'] = $coun.'/元';
		         // dump($clist);
		         //   exit;

		        if (!empty($clist)) {
		            //  $this->handler = new \PHPExcel();
		           	// $this->handler->getActiveSheet()->setTitle($Title);
		          
		            
		            $tableHeader = array(
		                '日期','用车事由', '出发地点', '目的地','起始读数','结束读数','公里数','用车人','出发时间','回公司时间','费用','备注'
		            );
		            $tableCols = array(
		                'time','content','s_place', 'e_place','q','e','km','uname','s_time','e_time','rmb','cont'
		            );
		            // $size = '派车反馈信息';
   
		            downloadExcel($clist, $tableHeader,$tableCols,'pcs'.'.xls');
		        }else{
		            $this->error('没有数据可以导出,请检查!');
		            exit;
		        }
		}else{
			echo '市外';
		}



	}





	//固定资产申请审批导出
	public function gdao()
	{
		$dertime = date('Y-m-d');
		// echo $dertime;
		// exit;
		$clist = M('look')->order('time desc')->where(['type'=>2,'look'=>2,'ju'=>0])->select();
		// dump($clist);
		// exit;
		// foreach ($clist as  $v) {
		// 	$coun += $v['zong']; 
		// }
		// $ctime = $clist[0]['time'];

		// $ulist = M('ucan')->where(['time'=>$ctime])->select();
		// $clist[0]['coun'] = $coun.'/元';
         // dump($clist);
         //   exit;

        if (!empty($clist)) {
             
           
          
            
            $tableHeader = array(
                '编号','品名', '规格', '单位','数量','预估单价','备注','申请人','所属部门'
            );
            $tableCols = array(
                'id','wname','xing', 'com','num','unit','content','uname','ment'
            );
            downloadExcel($clist, $tableHeader,$tableCols, 'pcs'.'.xls');
        }else{
            $this->error('没有数据可以导出,请检查!');
            exit;
        }



	}






	
}